package com.kkb.kkbportal.controller;

import com.github.pagehelper.PageInfo;
import com.kkb.kkbcommon.api.CommonPage;
import com.kkb.kkbcommon.api.CommonResult;
import com.kkb.kkbportal.domain.Recommend;
import com.kkb.kkbportal.service.RecommendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author leo
 * @title: Recommend
 * @projectName kkb-parent-v2
 * @description 内推模块前台controller
 * @date 2021/8/11 4:12 下午
 */
@RestController
@Api(tags = "内推信息管理", value = "内推信息管理")
@RequestMapping("/recommend")
public class RecommendController {

    @Autowired
    private RecommendService recommendService;

    /**
     * 分页查询
     *
     * @param condition 条件
     * @param pageNum   页码
     * @param pageSize  每页显示行数
     * @return
     */
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "condition", value = "内推筛选条件", dataType = "Recommend"),
            @ApiImplicitParam(name = "pageNum", value = "当前页数", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", defaultValue = "10", dataType = "int")
    })
    @GetMapping("/page")
    public CommonResult<CommonPage<Recommend>> listPage(Recommend condition,
                                                        @RequestParam(defaultValue = "1") Integer pageNum,
                                                        @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Recommend> page = recommendService.findPage(condition, pageNum, pageSize);
        CommonPage<Recommend> commonPage = CommonPage.restPage(page.getList());
        return CommonResult.success(commonPage);
    }

    /**
     * 条件查询
     *
     * @Author leo
     * @Date: 2021/8/11 4:45 下午
     */
    @ApiOperation("指定条件查询")
    @ApiImplicitParam(name = "id", value = "内推id", required = true, dataType = "Long")
    @PostMapping("/conditionQuery")
    public CommonResult<List<?>> conditionQuery(@RequestBody Recommend recommendByCondition) {
        List<Recommend> recommendList = recommendService.selectByCondition(recommendByCondition);
        return CommonResult.success(recommendList);
    }

}
